<script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.gears.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.silverlight.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.flash.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.browserplus.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="./resource/uploader/plupload.html5.js"></script>

<!-- <script type="text/javascript"  src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script> -->
<div id="content" class="upload">
    <form id="submit-form" method="post" action="dump.php">
        <div>
            <div id="filelist">No runtime found.</div>
            <br />
            <a id="pickfiles" href="javascript:;">[Select files]</a>
            <a id="uploadfiles" href="javascript:;">[Upload files]</a>
        </div>

        <input type="submit" />
    </form>
    <style>
        b{color:yellow};
    </style>
    <div style="background-color: black; color: white;" id="info"></div>
    <script type="text/javascript">
        // Custom example logic
        function $(id) {
            return document.getElementById(id);
        }


        var uploader = new plupload.Uploader({
            runtimes : 'flash,silverlight,browserplus',
            browse_button : 'pickfiles',
            max_file_size : '300mb',
            url : '<?php echo base_url(); ?>notatki/do_upload',
            resize : {width : 320, height : 240, quality : 90},
            flash_swf_url : '<?php echo base_url(); ?>resource/uploader/plupload.flash.swf',
            silverlight_xap_url : '<?php echo base_url(); ?>resource/uploader/plupload.silverlight.xap',
            filters : [
                {title : "Image files", extensions : "jpg,gif,png"},
                {title : "Zip files", extensions : "zip"}
            ],
            multipart: true,
            multipart_params: {
                '<?php echo $this->security->get_csrf_token_name() ?>' : '666'
            }
        });

        uploader.bind('Init', function(up, params) {
            $('filelist').innerHTML = "<div>Current runtime: " + params.runtime + "</div>";
        });

        uploader.bind('FilesAdded', function(up, files) {
            for (var i in files) {
                $('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
            }
        });

        uploader.bind('UploadFile', function(up, file) {
            $('submit-form').innerHTML += '<input type="hidden" name="file-' + file.id + '" value="' + file.name + '" />';
        });

        uploader.bind('UploadProgress', function(up, file) {
            $(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
        });

        uploader.bind('FileUploaded', function(up, file, response) {
            //            function concatObject(obj) {
            //                str='';
            //                for(prop in obj)
            //                {
            //                    str+=prop + " value :"+ obj[prop]+"\n";
            //                }
            //                return(str);
            //            }
            //
            //            alert(concatObject(response));
            $('info').innerHTML = response.response;
        });

        $('uploadfiles').onclick = function() {
            uploader.start();
            return false;
        };

        uploader.init();
    </script>
</div>